//
// Created by user on 20-5-5.
//

#include "Time.h"

Time time;

int getCmosTime(Time *time) {

    // 1. 关中断
    cli();

    // 2. 通过循环获取时间，循环条件是判断当前时间是否没有变化，如果变化了就再读一次，直到时间不变化了
    do {
        time->year = CMOS_READ(0x09) + CMOS_READ(0x32) * 0x100;
        time->month = CMOS_READ(0x08);
        time->day = CMOS_READ(0x07);
        time->hour = CMOS_READ(0x04);
        time->minute = CMOS_READ(0x02);
        time->second = CMOS_READ(0x00);
    } while (time->second != CMOS_READ(0x00));

    io_out8(0x70, 0x00);

    // 4. 开中断
//    sti();

    return 1;
}